package _interview100;

import _object.ListNode;

/**
 * 24. 两两交换链表中的节点
 */
public class No24 {
    public ListNode swapPairs(ListNode head) {
        ListNode sent = new ListNode(-1, head);
        ListNode pre = sent, cur = head, nex;
        while (cur != null && cur.next != null) {
            nex = cur.next;
            cur.next = nex.next;
            nex.next = cur;
            pre.next = nex;
            pre = cur;
            cur = cur.next;
        }
        return sent.next;
    }
}
